package com.ft.adbix.utils.http;

import com.ft.adbix.utils.data.synchronize.entity.DeviceData;
import com.ft.adbix.utils.http.client.AsyncHttpClient;
import com.ft.adbix.utils.http.listener.CommonAdListener;
import com.ft.adbix.utils.http.listener.HttpListener;
import com.ft.adbix.utils.json.Gson;

import java.util.HashMap;
import java.util.Map;

public class HttpHelper {

//    public static String ADBIX_BASE_URL = "http://adx-bid-test.fntmob.com/adx-alliance-test";
//    public static String ADBIX_BASE_URL = "https://adx-bid-test.fntmob.com";
    public static String ADBIX_BASE_URL = "https://adx-bid.fntmob.com";
//    public static String ADBIX_BASE_URL = "http://118.31.1.142:7091";
    public static String ADBIX_AD_REQUEST_URL = ADBIX_BASE_URL+"/adx-alliance-v2";
    //    public static String URL_FT = "https://newappapitest.fntmob.com/";

    private static AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
    private static Map<String, Object> queryMap = new HashMap<>();
    private static Map<String, String> headerMap = new HashMap<>();

    private static volatile HttpHelper mInstance;
    public static Gson gson = new Gson();

    public static HttpHelper getInstance() {
        if (mInstance == null) {
            synchronized (HttpHelper.class) {
                if (mInstance == null) {
                    mInstance = new HttpHelper();
                }
            }
        }
        return mInstance;
    }

    public static void init() {

    }

    public static void setDeviceData(DeviceData data) {
        queryMap.put("device", gson.toJson(data));
    }

    public static void post(String url, Map<String, Object> params, HttpListener listener) {
        asyncHttpClient.post(url, params, headerMap, listener);
    }

    public static void loadAd(Map<String, Object> adParams, CommonAdListener listener) {
        asyncHttpClient.post(ADBIX_AD_REQUEST_URL, adParams, listener);
    }

}
